#pragma once
#include "RenderingPrefix.h"
#include "RenderGraphParameter.h"
#include "Runtime/CGI/CGICommandList.h"
#include "Runtime/CGI/CGIResource.h"
namespace Alice
{
    class RDGDispatchPassBuilder;
    class RDGPass
    {
    public:
        const RDGParameterStruct mParameterStruct;
        const ERHIPipeline mPipeline;
        RDGPass(RDGParameterStruct InParameterStruct,ERDGPassFlags InFlags);
        ERHIPipeline GetPipeline() const
        {
            return mPipeline;
        }
        virtual void LaunchDispatchPassTasks(RDGDispatchPassBuilder& DispatchPassBuilder) {}
    };
    class RDGDispatchPass:public RDGPass
    {
    public:
        std::vector<CGICommandListImmediate::FQueuedCommandList> mCommandLists;
        RDGDispatchPass(RDGParameterStruct InParameterStruct,ERDGPassFlags InFlags)
        : RDGPass(InParameterStruct,InFlags)
        {
            
        }
    };
    template <typename ParameterStructType, typename LaunchLambdaType>
    class TRDGDispatchPass : public RDGDispatchPass
    {
    public:
        TRDGDispatchPass(
            const ParameterStructType* InParameterStruct,
            ERDGPassFlags InPassFlags,
            LaunchLambdaType&& InLaunchLambda)
            : RDGDispatchPass(RDGParameterStruct(InParameterStruct), InPassFlags)
            , LaunchLambda(std::move(InLaunchLambda))
        {}
    private:
        LaunchLambdaType LaunchLambda;
        void LaunchDispatchPassTasks(RDGDispatchPassBuilder& DispatchPassBuilder)
        {
            LaunchLambda(DispatchPassBuilder);
        }
    };
    class RDGDispatchPassBuilder
    {
    public:
        RDGDispatchPassBuilder(RDGDispatchPass* InPass)
            : mPass(InPass)
        {
            BasePassParameter*basePassParameter=(BasePassParameter*)(mPass->mParameterStruct.mContents);
            mRenderPassInfo=new CGIRenderPassInfo;
            mRenderPassInfo->mColorRenderTargets.RenderTarget=(CGITexture*)basePassParameter->mRenderTargetBindingSlots[0].GetTexture()->mCGIResource;
            mRenderPassInfo->mColorRenderTargets.Action=ERenderTargetActions::Clear_Store;
            mRenderPassInfo->mbIsSwapChain=true;
            mRenderPassInfo->mbSwapChainImageIndex=0;
        }
        CGICommandList* CreateCommandList();
        void Finish();
        RDGDispatchPass* mPass;
        CGIRenderPassInfo* mRenderPassInfo;
    };
}